package com.example.warehouse.sys.service.impl;

import com.example.warehouse.sys.dao.persist.respository.IUserRoleRepository;
import com.example.warehouse.sys.pojo.entity.SysUserRole;
import com.example.warehouse.sys.pojo.param.SysUserRoleAddNewParam;
import com.example.warehouse.sys.service.IUserRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserRoleServiceImpl implements IUserRoleService {
    public UserRoleServiceImpl() {
        log.debug("创建业务类对象: UserRoleService");
    }

    @Autowired
    private IUserRoleRepository userRoleRepository;
    @Override
    public void addRoleToUser(SysUserRoleAddNewParam sysUserRoleAddNewParam) {
        SysUserRole sysUserRole = new SysUserRole();
        if (sysUserRoleAddNewParam.getRoleId()==null){
            String message="给用户添加角色失败";
            log.warn(message);
            throw new SecurityException(message);
        }
        BeanUtils.copyProperties(sysUserRoleAddNewParam,sysUserRole);
        userRoleRepository.insertByRoleIdAndUserId(sysUserRole);
    }
}
